package com.java.design.observer.customer;

/**
 * 新增一个天气订阅者*
 * @author Tony
 */
public class HeatIndexDisplay implements ObServer,Display{

    private float temp;

    float humidity;

    private Subject weatherData;

    private float heatIndex;

    public HeatIndexDisplay(WeatherData weatherData){
        this.weatherData = weatherData;
        weatherData.registerObserver(this);

    }

    @Override
    public void display() {
        System.out.println("Heat Index: " + heatIndex);
    }

    @Override
    public void update(float temp, float humidity, float pressure) {
        this.temp = temp;
        this.humidity = humidity;
        this.heatIndex = (float) (-42.379 + (2.04901523 * temp) + (10.14333127 * humidity) - (0.22475541 * temp*  humidity) - (6.83783e-3 * temp *temp) - (5.481717e-2 *  humidity* humidity)
                        + (1.22874e-3 *  temp *temp * temp * humidity) + (8.5282e-4 * temp * humidity* humidity) - (1.99e-6 * temp *temp * humidity* humidity));
        display();
    }
}
